package edu.cicese.alz;

import edu.cicese.alz.swing.ColoredToggleButton;
import edu.cicese.alz.swing.CustomButton;
import edu.cicese.alz.swing.CustomToggleButton;
import edu.cicese.alz.swing.SwingUtil;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JToggleButton;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 29/05/12
 * Time: 04:34 PM
 */
public class SwingComponent extends JFrame {

//	private int minWidth;
//	private int minHeight;

	public SwingComponent(int minWidth, int minHeight, int maxWidth, int maxHeight, String title) {
		this(minWidth, minHeight, title);
		setMax(maxWidth, maxHeight);
	}

	public SwingComponent(int minWidth, int minHeight, String title) {
		setMin(minWidth, minHeight);
		setInitialLocation();
		setTitle(title);
	}

	public SwingComponent() {}

	public void setMin(int minWidth, int minHeight) {
		setPreferredSize(new Dimension(minWidth, minHeight));
		setMinimumSize(getPreferredSize());
	}

	public void setMax(int maxWidth, int maxHeight) {
		setMaximumSize(new Dimension(maxWidth, maxHeight));
	}

	public void setInitialLocation() {
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		Rectangle window = getBounds();
		setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
	}

	public void closeWindow(boolean acceptOrCancel) {
		if (acceptOrCancel) {
			setVisible(false);
			dispose();
		}
//		frmTagCreation.setEnabled(true);
//		frmTagCreation.toFront();
//		AWTUtilities.setWindowOpacity(frmTagCreation, 1f);
	}

	public void addButton(JButton button, String label, String toolTipText, String iconName, Container container) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		SwingUtil.addButton(button, label, toolTipText, icon, container);
	}

	public JButton getButton(String label, String toolTipText, String iconName) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.getButton(label, toolTipText, icon);
	}

	public Icon getIcon(String iconName) {
		return new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
	}

	public void addToggleButton(JButton button, String label, String toolTipText, String iconName, Container container) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		SwingUtil.addToggleButton(button, label, toolTipText, icon, container);
	}

	public void addToggleButton(ColoredToggleButton button, String label, int width, int height, String toolTipText, Container container) {
		SwingUtil.addToggleButton(button, label, toolTipText, null, container);
		SwingUtil.setSize(button, width, height);
	}

	public void addButton(JButton button, String text, int width, int height, String toolTipText, String iconName, Container container) {
		addButton(button, text, toolTipText, iconName, container);
		SwingUtil.setSize(button, width, height);
	}

	public void addButton(JButton button, String text, int width, int height, String toolTipText, Container container) {
		SwingUtil.addButton(button, text, width, height, toolTipText, container);
	}

	public void addButton(JButton button, String text, int x, int y, int width, int height, String toolTipText, String iconName, Container container) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		SwingUtil.addButton(button, text, x, y, width, height, toolTipText, icon, container);
	}

	public void addButtonBackground(JButton button, String text, int width, int height, String toolTipText, String iconName, Container container) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		Icon rIcon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + "O.png"));
		Icon pIcon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + "P.png"));
		SwingUtil.addButtonBackground(button, text, width, height, toolTipText, icon, rIcon, pIcon, container);
	}

	public JButton createButton(String text, String toolTipText, String iconName) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createButton(text, toolTipText, icon);
	}

	public JButton createButton(String text, String toolTipText, String iconName, Color color) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createButton(text, toolTipText, icon, color);
	}

	public JButton createButton(String text, String toolTipText, String iconName, int width, int height) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createButton(text, toolTipText, icon, width, height);
	}

	public CustomButton createCustomButton(String text, String toolTipText, String iconName) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createCustomButton(text, toolTipText, icon);
	}

	public CustomButton createCustomButton(String text, String toolTipText, String iconName, Color color) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createCustomButton(text, toolTipText, icon, color);
	}

	public CustomButton createCustomButton(String text, String toolTipText, String iconName, int width, int height) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createCustomButton(text, toolTipText, icon, width, height);
	}

	public JButton createButtonBackground(String text, int width, int height, String toolTipText, String iconName) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		Icon rIcon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + "O.png"));
		Icon pIcon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + "P.png"));
		return SwingUtil.createButtonBackground(text, width, height, toolTipText, icon, rIcon, pIcon);
	}

	public CustomToggleButton createCustomToggleButton(String text, String toolTipText, String iconName) {
		return createCustomToggleButton(text, toolTipText, iconName, false, SwingUtil.cBackground);
	}

	public CustomToggleButton createCustomToggleButton(String text, String toolTipText, String iconName, boolean selected) {
		return createCustomToggleButton(text, toolTipText, iconName, selected, SwingUtil.cBackground);
	}

	public CustomToggleButton createCustomToggleButton(String text, String toolTipText, String iconName, boolean selected, Color bgColor) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createCustomToggleButton(text, toolTipText, icon, selected, bgColor);
	}

	public JToggleButton createToggleButton(String text, String toolTipText, String iconName) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createToggleButton(text, toolTipText, icon, false);
	}

	public JToggleButton createToggleButton(String text, String toolTipText, String iconName, boolean selected) {
		Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/" + iconName + ".png"));
		return SwingUtil.createToggleButton(text, toolTipText, icon, selected);
	}
}
